import { reactive, computed, toRefs } from 'vue';
import { PaginationQuery, Pagination } from '@/types/table';
import { TableState, CheckAble } from '@/types/table';
import { getskuGoodsSku, getCetegory } from '@/api/goods';
export interface state1 {
    cetegoryList: NormalObj[];
}
const tableQuery: PaginationQuery = reactive({
    page: 0,
    size: 9999,
    sort: 'id,desc',
    skuSpecsId: '',
});
// 编辑用户
const state1: state1 = reactive({
    cetegoryList: [],
});
// 编辑用户
const state: TableState & CheckAble = reactive({
    dataSource: [],
    selectedRow: {},
    selectedRowKeys: [],
    visible: false,
    loading: false,
    pagination: {
        total: 0,
        current: computed(() => tableQuery.page + 1),
    },
});

// 获取table数据
const getCetegoryData = async (tableQuery: PaginationQuery) => {
    state.loading = true;
    const { content } = await getCetegory(tableQuery);
    state.loading = false;
    state1.cetegoryList = content;
};
// 获取表格数据
const getskuGoodsSkuList = async (params: PaginationQuery) => {
    const { content } = await getskuGoodsSku(params);
    state.loading = false;
    state.dataSource = content;
};

// 选择项发生改变
const onSelectChange = (keys: (string | number)[]) => {
    state.selectedRowKeys = keys;
};
const handleCetegory = (keys: (string | number)[]) => {
    getskuGoodsSkuList(tableQuery);
};

export default {
    tableQuery,
    getskuGoodsSkuList,
    ...toRefs(state),
    ...toRefs(state1),
    handleCetegory,
    onSelectChange,
    getCetegoryData,
};
